package com.alen.sun.dao;

import com.alen.sun.bean.Folk;
import com.alen.sun.bean.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface RoomMapper {

    //查找房间存在
    @Select("SELECT count(*) FROM room WHERE room_num = #{roomNum}")
    Integer  selectRoom(Room room);

    //添加房间
    @Insert("INSERT INTO room (room_num, room_status) VALUES (#{roomNum}, #{roomStatus})")
    Boolean addRoom(Room room);

    //修改房间信息
    @Update("UPDATE room SET room_status = #{roomStatus} WHERE room_num = #{roomNum}")
    Boolean updateRoom(Room room);

    //删除房间
    @Delete("DELETE FROM room WHERE room_num = #{roomNum}")
    Boolean deleteRoom(Room room);


    //批量删除
    @Delete({
            "<script>",
            "delete from room where room_num in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from room")
    Long count();

    /**
     * 分页查询,获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from room limit #{start},#{pageSize}")
    List<Room> page(Integer start, Integer pageSize);

    /**
     * 分页查询空闲房间,获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from room WHERE room_status = 0 limit #{start},#{pageSize} ")
    List<Room> pageFreeRoom(Integer start, Integer pageSize);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from room WHERE room_status = 0")
    Long countFreeRoom();

    //网页搜索功能 聚合模糊查询,房间号
    @Select("SELECT * FROM room " +
            "WHERE room_num LIKE CONCAT('%', #{keywords}, '%') ")
    List<Room> searchByKeywords(String keywords);

    //在老人管理页面,获取空闲房间
    @Select("SELECT room_num FROM room WHERE room_status = 0")
    List<Map<String,String>> getFreeRoom();

}
